package cn.com.note.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import cn.com.note.R;

/**
 * Created by sunfulin on 2019/6/17.
 */

public class LoadingButton extends LinearLayout implements View.OnClickListener {
    ProgressBar progressBar;
    TextView tvContent;

    public LoadingButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);
    }

    View.OnClickListener onClickListener;

    public void setOnClick(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    private void initView(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.view_loading_button, this);
        progressBar = findViewById(R.id.loading);
        tvContent = findViewById(R.id.tvContent);
        this.setOnClickListener(this);
    }

    public void setText(String txt) {
        setShowLoading(false, txt);
    }

    public void setShowLoading(boolean isShow, String txt) {
        progressBar.setVisibility(isShow ? VISIBLE : GONE);
        tvContent.setText(txt);
    }

    @Override
    public void onClick(View v) {
        if (onClickListener != null) {
            onClickListener.onClick(v);
        }

    }
}
